package org.eweb4j.solidbase.user.web;

import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;

import org.eweb4j.mvc.action.annotation.ShowValMess;
import org.eweb4j.solidbase.user.model.UserCons;

import com.google.code.kaptcha.Constants;

@Path("${UserConstant.MODEL_NAME}")
public class RegisterAction extends BaseAction {
	@GET
	@Path("register")
	public String register() {
		return UserCons.REGISTER_ACTION_RESULT();
	}

	@POST
	@Path("register")
	@ShowValMess("${UserConstant.REGISTER_PAGE}")
	public String doRegister() {
		try {
			String sessionAuthcode = (String) session
					.getAttribute(Constants.KAPTCHA_SESSION_KEY);
			userService.register(sessionAuthcode, user);

		} catch (Exception e) {
			request.setAttribute("registerError", e.getMessage());
			return UserCons.REGISTER_ACTION_RESULT();
		}

		return UserCons.REGISTER_SUCCESS_INFO();
	}
}
